*** Builder log created: {2021-10-26 14:01:55}
*** Builder log completed: {2021-10-26 14:02:09}

  ___  ____  ____  ____  ____ ©
 /__    /   ____/   /   ____/      17.0
___/   /   /___/   /   /___/       MP—Parallel Edition

 Statistics and Data Science       Copyright 1985-2021 StataCorp LLC
                                   StataCorp
                                   4905 Lakeway Drive
                                   College Station, Texas 77845 USA
                                   800-STATA-PC        https://www.stata.com
                                   979-696-4600        stata@stata.com

Stata license: Unlimited-user 4-core network, expiring 21 Jul 2022
Serial number: 501709301051
  Licensed to: Levi Boxell
               

Notes:
      1. Stata is running in batch mode.
      2. Unicode is supported; see help unicode_advice.
      3. More than 2 billion observations are allowed; see help obs_advice.
      4. Maximum number of variables is set to 5,000; see help set_maxvar.

. do "source/descriptive/anes_cses_comparison.do" 

. clear all

. 
. *
. * Clean 2016
. *
. use "source/externals/orig/anes/2016/anes_timeseries_2016.dta", clear

. * full sample post-election weight
. gen weight = V160102

. 
. * CSES
. gen cses_like_D     = V162283

. replace cses_like_D = . if cses_like_D < 0
(714 real changes made, 714 to missing)

. gen cses_like_R     = V162284

. replace cses_like_R = . if cses_like_R < 0
(671 real changes made, 671 to missing)

. 
. * ANES
. gen anes_feel_D = V161095

. replace anes_feel_D = . if anes_feel_D < 0
(70 real changes made, 70 to missing)

. gen anes_feel_R = V161096

. replace anes_feel_R = . if anes_feel_R < 0
(86 real changes made, 86 to missing)

. 
. gen anes_party_R = (V161155 == 2)

. gen anes_party_D = (V161155 == 1)

. 
. gen anes_polar     = (anes_feel_R - anes_feel_D) if anes_party_R == 1
(3,053 missing values generated)

. replace anes_polar = (anes_feel_D - anes_feel_R) if anes_party_D == 1
(1,425 real changes made)

. 
. gen cses_polar_anes_pty     = 10 * (cses_like_R - cses_like_D) if anes_party_
> R == 1
(3,246 missing values generated)

. replace cses_polar_anes_pty = 10 * (cses_like_D - cses_like_R) if anes_party_
> D == 1
(1,216 real changes made)

. 
. * Drop Sample
. keep if anes_polar != . & cses_polar_anes_pty != . & weight > 0
(2,060 observations deleted)

. keep anes_* cses_* weight

. gen year = 2016

. tempfile temp2016

. save `temp2016'
file /var/folders/nm/bkdnfkv12s9f6sf7vjkbbg6c0000gn/T//St34079.000001 saved
    as .dta format

. 
. 
. *
. * Clean 2012
. *
. use "source/externals/orig/anes/2012/anes_timeseries_2012.dta", clear

. * weight for full sample
. gen weight = weight_full

. 
. * CSES
. gen cses_like_D     = cses_dptylike

. replace cses_like_D = . if cses_like_D < 0
(478 real changes made, 478 to missing)

. gen cses_like_R     = cses_rptylike

. replace cses_like_R = . if cses_like_R < 0
(476 real changes made, 476 to missing)

. 
. * ANES
. gen anes_feel_D = ft_dem

. replace anes_feel_D = . if anes_feel_D < 0
(58 real changes made, 58 to missing)

. gen anes_feel_R = ft_rep

. replace anes_feel_R = . if anes_feel_R < 0
(63 real changes made, 63 to missing)

. 
. gen anes_party_R = (pid_self == 2)

. gen anes_party_D = (pid_self == 1)

. 
. gen anes_polar     = (anes_feel_R - anes_feel_D) if anes_party_R == 1
(4,528 missing values generated)

. replace anes_polar = (anes_feel_D - anes_feel_R) if anes_party_D == 1
(2,356 real changes made)

. 
. gen cses_polar_anes_pty     = 10 * (cses_like_R - cses_like_D) if anes_party_
> R == 1
(4,626 missing values generated)

. replace cses_polar_anes_pty = 10 * (cses_like_D - cses_like_R) if anes_party_
> D == 1
(2,192 real changes made)

. 
. * Drop Sample
. keep if anes_polar != . & cses_polar_anes_pty != . & weight > 0
(2,437 observations deleted)

. keep anes_* cses_* weight

. gen year = 2012

. tempfile temp2012

. save `temp2012'
file /var/folders/nm/bkdnfkv12s9f6sf7vjkbbg6c0000gn/T//St34079.000002 saved
    as .dta format

. 
. 
. 
. *
. * Clean 2008
. *
. use "source/externals/orig/anes/2008/anes_timeseries_2008.dta", clear

. * post-election sample weight
. gen weight = V080102

. 
. * CSES
. gen cses_like_D     = V085187a

. replace cses_like_D = . if cses_like_D < 0
(260 real changes made, 260 to missing)

. gen cses_like_R     = V085187b

. replace cses_like_R = . if cses_like_R < 0
(262 real changes made, 262 to missing)

. 
. * ANES
. gen anes_feel_D = V083044a

. replace anes_feel_D = . if anes_feel_D < 0
(63 real changes made, 63 to missing)

. gen anes_feel_R = V083044b

. replace anes_feel_R = . if anes_feel_R < 0
(70 real changes made, 70 to missing)

. 
. gen anes_party_R = (V083097 == 2)

. gen anes_party_D = (V083097 == 1)

. 
. gen anes_polar     = (anes_feel_R - anes_feel_D) if anes_party_R == 1
(1,895 missing values generated)

. replace anes_polar = (anes_feel_D - anes_feel_R) if anes_party_D == 1
(953 real changes made)

. 
. gen cses_polar_anes_pty     = 10 * (cses_like_R - cses_like_D) if anes_party_
> R == 1
(1,926 missing values generated)

. replace cses_polar_anes_pty = 10 * (cses_like_D - cses_like_R) if anes_party_
> D == 1
(872 real changes made)

. 
. * Drop Sample
. keep if anes_polar != . & cses_polar_anes_pty != . & weight > 0
(1,073 observations deleted)

. keep anes_* cses_* weight

. gen year = 2008

. tempfile temp2008

. save `temp2008'
file /var/folders/nm/bkdnfkv12s9f6sf7vjkbbg6c0000gn/T//St34079.000003 saved
    as .dta format

. 
. 
. *
. * Clean 2004
. *
. use "source/externals/orig/anes/2004/anes2004TS.dta", clear

. * post-election sample weight
. gen weight = V040102

. 
. * CSES
. gen cses_like_D     = V045257
(146 missing values generated)

. replace cses_like_D = . if cses_like_D > 10
(22 real changes made, 22 to missing)

. gen cses_like_R     = V045258
(146 missing values generated)

. replace cses_like_R = . if cses_like_R > 10
(19 real changes made, 19 to missing)

. 
. * ANES
. gen anes_feel_D = V043049

. replace anes_feel_D = . if anes_feel_D > 100
(34 real changes made, 34 to missing)

. gen anes_feel_R = V043050

. replace anes_feel_R = . if anes_feel_R > 100
(36 real changes made, 36 to missing)

. 
. gen anes_party_R = (V043114 == 1)

. gen anes_party_D = (V043114 == 2)

. 
. gen anes_polar     = (anes_feel_R - anes_feel_D) if anes_party_R == 1
(869 missing values generated)

. replace anes_polar = (anes_feel_D - anes_feel_R) if anes_party_D == 1
(375 real changes made)

. 
. gen cses_polar_anes_pty     = 10 * (cses_like_R - cses_like_D) if anes_party_
> R == 1
(895 missing values generated)

. replace cses_polar_anes_pty = 10 * (cses_like_D - cses_like_R) if anes_party_
> D == 1
(327 real changes made)

. 
. * Drop Sample
. keep if anes_polar != . & cses_polar_anes_pty != . & weight > 0
(575 observations deleted)

. keep anes_* cses_* weight

. gen year = 2004

. tempfile temp2004

. save `temp2004'
file /var/folders/nm/bkdnfkv12s9f6sf7vjkbbg6c0000gn/T//St34079.000004 saved
    as .dta format

. 
. 
. *
. * Clean 1996
. *
. use "source/externals/orig/anes/1996/nes96.dta", clear

. * Time-series weight (post)
. gen weight = V960005B
(180 missing values generated)

. 
. * CSES
. gen cses_like_D     = V961470

. replace cses_like_D = . if cses_like_D > 10
(200 real changes made, 200 to missing)

. gen cses_like_R     = V961471

. replace cses_like_R = . if cses_like_R > 10
(202 real changes made, 202 to missing)

. 
. * ANES
. gen anes_feel_D = V960292

. replace anes_feel_D = . if anes_feel_D > 100
(27 real changes made, 27 to missing)

. gen anes_feel_R = V960293

. replace anes_feel_R = . if anes_feel_R > 100
(35 real changes made, 35 to missing)

. 
. gen anes_party_R = (V960417 == 2)

. gen anes_party_D = (V960417 == 1)

. 
. gen anes_polar     = (anes_feel_R - anes_feel_D) if anes_party_R == 1
(1,245 missing values generated)

. replace anes_polar = (anes_feel_D - anes_feel_R) if anes_party_D == 1
(649 real changes made)

. 
. gen cses_polar_anes_pty     = 10 * (cses_like_R - cses_like_D) if anes_party_
> R == 1
(1,286 missing values generated)

. replace cses_polar_anes_pty = 10 * (cses_like_D - cses_like_R) if anes_party_
> D == 1
(596 real changes made)

. 
. * Drop Sample
. keep if anes_polar != . & cses_polar_anes_pty != . & weight > 0
(703 observations deleted)

. keep anes_* cses_* weight

. gen year = 1996

. tempfile temp1996

. save `temp1996'
file /var/folders/nm/bkdnfkv12s9f6sf7vjkbbg6c0000gn/T//St34079.000005 saved
    as .dta format

. 
. 
. ** AGGREGATE
. use `temp1996', clear

. append using `temp2004'

. append using `temp2008'

. append using `temp2012'

. append using `temp2016'

. 
. 
. * Bootstrap
. program define get_reg, rclass
  1.         preserve
  2.         collapse (mean) anes_polar cses_polar_anes_pty [weight = weight], 
> by(year)
  3.         
.         reg anes_polar year
  4.         local anes_slope = _b[year]
  5.         
.         reg cses_polar_anes_pty year
  6.         local cses_slope = _b[year]
  7.         restore
  8.         return scalar diff = `anes_slope' - `cses_slope'
  9. end

. 
. bootstrap r(diff), reps(500) strata(year) seed(2020) : get_reg
(running get_reg on estimation sample)

warning: get_reg does not set e(sample), so no observations will be excluded
         from the resampling because of missing values or other reasons. To
         exclude observations, press Break, save the data, drop any
         observations that are to be excluded, and rerun bootstrap.

Bootstrap replications (500)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
..................................................    50
..................................................   100
..................................................   150
..................................................   200
..................................................   250
..................................................   300
..................................................   350
..................................................   400
..................................................   450
..................................................   500

Bootstrap results

Number of strata = 5                                     Number of obs = 8,584
                                                         Replications  =   500

      Command: get_reg
        _bs_1: r(diff)

------------------------------------------------------------------------------
             |   Observed   Bootstrap                         Normal-based
             | coefficient  std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
       _bs_1 |   .1221594   .0683626     1.79   0.074    -.0118289    .2561477
------------------------------------------------------------------------------

. mat table = r(table)

. matrix_to_txt, matrix(table) saving("build/descriptive/anes_cses_bootstrap.tx
> t") title("<tab:anes_cses_bootstrap>")

. 
. * Collapse and save
. collapse (mean) anes_polar cses_polar_anes_pty [weight = weight], by(year)
(analytic weights assumed)

. outfile using "build/descriptive/anes_cses_comparison.txt", comma

. 
. 
end of do-file
